<include file="Public:header" />
<include file="Public:leftside" />

<style type="text/css">
	.modal {
		height: 600px;
	}
	
	.modal-infp-style {
		width: 90%;
		margin: 10px auto;
	}
	
	.modal-infp-style table {
		width: 100%;
	}
	
	.modal-infp-style table tr td {
		border: 1px solid #e6e6e6;
		padding: 8px;
	}
	
	a:hover {
		cursor: pointer;
	}
	.child{background: #eee!important;}
	.par{display: block;float: left;background: #4cc0c1;	color: #fff;width: 20px;height: 20px;text-align: center;margin-right: 5px;}
</style>
<php>
	$ids=explode(',',$rs['bids']);
</php>
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
				<li> <i class="icon-home home-icon"></i>
					<a href="/">首页</a>
				</li>
				<li><a href="/Users/admin_index.html">会员管理</a></li>
				<li><a href="JavaScript:;">权限配置</a></li>
		</ul>
	</div>
	<section class="scrollable wrapper">

		
		<section class="panel panel-default">
			<div class="table-responsive">
				<table id="sample-table-1" class="table  table-bordered table-hover">
					<thead>
					<tr>
						<th class="center" width="20">
							<input type="checkbox">
						</th>
						<th>栏目名</th>


					</tr>
					</thead>
					<tbody>
					<volist name="new_data" id="row">
						<tr>
							<td>
								<php>
									if(in_array($row['id'],$ids)){
								</php>
								<input type="checkbox" value="<?=$row['id']?>" name="bids" class="fu" checked>
								<php>
									}else{
								</php>
								<input type="checkbox" value="<?=$row['id']?>" name="bids" class="fu">
								<php>}</php>
							</td>
							<td style="font-weight:bold;">
								<a href="javascript:;" onclick="show(<?=$row['id']?>)" class="par partent<?=$row['id']?>">+</a>
								<?=$row['name']?>

							</td>

						</tr>
						<foreach name="row['child']" item="v">
							<tr class="child son{$row['id']}" style="display: none;" >
								<td>
									<php>
										if(in_array($row['id'],$ids)){
									</php>
									<input type="checkbox" value="<?=$v['id']?>" name="bids" class="check_son<?=$row['id']?>" checked>
									<php>
										}else{
									</php>
									<input type="checkbox" value="<?=$v['id']?>" name="bids" class="check_son<?=$row['id']?>">
									<php>
										}
									</php>
								</td>
								<td style="font-weight:bold;">
									├─<?=$v['name']?>
								</td>

							</tr>

						</foreach>
					</volist>
					</tbody>
				</table>

			</div>

			<div class="col-md-offset-1 col-md-9" style="margin-top: 15px;">
				<button class="btn btn-primary btn-big bq" value="保存" type="button">保存</button>
				&nbsp; &nbsp; &nbsp;
				<button class="btn btn-primary btn-big btn-danger" value="取消" type="button" onclick="history.back(-1);">取消</button>
			</div>

		</section>

	</section>
	<input type="hidden" id="u_id" value="{$_GET['id']}">
</div>
<script src="/Partner/static/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/js/layer2.1/layer.js"></script>
<link href="/static/css/jquery.mCustomScrollbar.min.css" rel="stylesheet">
<script type="text/javascript" src="/static/js/jquery.mCustomScrollbar.concat.min.js"></script>
<include file="Public:footer" />
<script>
	function show(id) {
		$('.son'+id).toggle();
		var t=$('.partent'+id).html();
		if(t=='+'){
            $('.partent'+id).html('-');
		}else{
            $('.partent'+id).html('+');
		}
    }
    $(function () {
		$('.fu').click(function () {
			var id=$(this).val();
            if($(this).is(':checked')) {
                $('.check_son'+id).prop('checked',true);
            }else{
                $('.check_son'+id).prop('checked',false);
			}

        })
		$('.bq').click(function () {
            var adIds=null;
            $("input:checkbox[name=bids]:checked").each(function(i){
                if(0==i){
                    adIds = $(this).val();
                }else{
                    adIds += (","+$(this).val());
                }
            });

            var uid=$('#u_id').val();
            $.ajax({
                type: "post",
                url: "{:U('users/edit_rbac')}",
                data: {
                    'uid': uid,
                    'adIds': adIds
                },
                success: function(data) {
                    if(data==1){
                        layer.msg('提交成功');
                        setTimeout("location.reload()",1000);
                    }
                    if(data==0){
                        layer.msg('提交失败');
                    }

                }
            });

            console.log(adIds);
        })
    })
</script>

